"""
@Author    : ghenyar
@Time      : 2025/9/1 10:46
@File      : menu_model
@Desc      : 菜单权限
"""
from datetime import datetime
from sqlalchemy import BigInteger, String, SmallInteger, Boolean, Integer, DateTime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from app.models import DatabaseModel, table_prefix


class MenuModel(DatabaseModel):
    __tablename__ = f"{table_prefix}menu"
    __table_args__ = {"comment": "菜单目录表"}

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="菜单目录ID")
    label: Mapped[str] = mapped_column(String(100), nullable=False, comment="标题")
    name: Mapped[str|None] = mapped_column(String(100), nullable=True, comment="名称")
    p_id: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0, comment="上级菜单目录ID")
    p_label: Mapped[str | None] = mapped_column(String(100), nullable=True, default="顶级目录",
                                                comment="上级菜单目录名称")
    types: Mapped[int] = mapped_column(SmallInteger, default=1, comment="类型 1:目录 2:菜单 3:按钮")
    code: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="权限码")
    e_link: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否外部链接")
    url: Mapped[str | None] = mapped_column(String(255), nullable=True, comment="地址(组件路径，外部链接)")
    is_hide: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否菜单中隐藏 True:是  False:否")
    icon: Mapped[str | None] = mapped_column(String(100), nullable=True, comment="菜单图标")
    sort: Mapped[int] = mapped_column(Integer, nullable=True, default=100, comment="序列")
    is_delete: Mapped[bool] = mapped_column(Boolean, nullable=True, default=False,
                                            comment="软删除  True:删除  False:否")
    created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now(),
                                                 comment="创建时间")
    updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, onupdate=func.now(),
                                                        comment="更新时间")
